package com.macro.mall.portal.domain;

import com.thoughtworks.xstream.XStream;
import com.thoughtworks.xstream.annotations.XStreamAlias;
import com.thoughtworks.xstream.annotations.XStreamConverter;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import me.chanjar.weixin.common.util.xml.XStreamCDataConverter;
import me.chanjar.weixin.common.util.xml.XStreamInitializer;

@Data
@Builder(builderMethodName = "newBuilder")
@NoArgsConstructor
@AllArgsConstructor
@XStreamAlias("xml")
public class TestPayResponse {
    // 公众账号ID
    @XStreamAlias("appid")
    @XStreamConverter(value = XStreamCDataConverter.class)
    private String appid;

    // 用户标识
    @XStreamAlias("openid")
    @XStreamConverter(value = XStreamCDataConverter.class)
    private String openid;

    // 商户号
    @XStreamAlias("mch_id")
    @XStreamConverter(value = XStreamCDataConverter.class)
    private String mchId;

    //    是否关注公众账号
    @XStreamAlias("is_subscribe")
    @XStreamConverter(value = XStreamCDataConverter.class)
    private String isSubscribe;

    //    随机字符串
    @XStreamAlias("nonce_str")
    @XStreamConverter(value = XStreamCDataConverter.class)
    private String nonceStr;

    //    商品ID
    @XStreamAlias("product_id")
    @XStreamConverter(value = XStreamCDataConverter.class)
    private String productId;

    //    签名
    @XStreamAlias("sign")
    @XStreamConverter(value = XStreamCDataConverter.class)
    private String sign;

    public static String toXml(TestPayResponse response) {
        XStream xstream = XStreamInitializer.getInstance();
        xstream.autodetectAnnotations(true);
        return xstream.toXML(response).replace("\n", "").replace("  ", "");
    }
}
